/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


var $ = jQuery.noConflict();

$(document).ready(function(){
    $("select").parent("span").addClass("select-custom").append("<a class='select-text'></a>");
    $(".select-custom").each(function(){
        var text = $(this).find("option:selected").text();
        if(text.length === 0){
            var text =  $(this).find("select option:first-child").text();
        }
        $(this).find(".select-text").text(text);
    });
    
    $(document).on("change",".select-custom",function(){
        var text = $(this).find("option:selected").text();
        $(this).find(".select-text").text(text);
    });
});

function convertimage(id, id_parse, img_show)
{
    var id = id;
    var id_parse = id_parse;
    var img_show = img_show;
    var filesSelected = document.getElementById(id).files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) 
        {
            $("#"+id_parse).attr('value', fileLoadedEvent.target.result);
            $("#"+id_parse+"check").val('1');
            $("#"+img_show).attr('src', fileLoadedEvent.target.result);
        };

        fileReader.readAsDataURL(fileToLoad);
    }
}

function exportToExcel()
{
    var data='<table border="1">'+jQuery("#Categrories").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
    jQuery('body').prepend("<form method='post' action="+'http://export.babybean.vn/exportexcel.php'+" style='display:none' id='Categroriesss'><input type='text' name='tableData' value='"+data+"' ></form>");
    
    jQuery('#Categroriesss').submit();//.remove();
    //setTimeout(function(){closeIframe();}, 5000);
alert('sdfd');
    return false;
}
function exportToDoc()
{
    var data='<table border="1" align="center">'+jQuery("#Categrories").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
    jQuery('body').prepend("<form method='post' action="+'http://export.babybean.vn/exportdoc.php'+" style='display:none' id='Categroriess'><input type='text' name='tableData' value='"+data+"' ></form>");
    jQuery('#Categroriess').submit();//.remove();
    //setTimeout(function(){closeIframe();}, 5000);
    return false;
}


function OpenPop(popUrl, heights, widths) {
			var popUrl = popUrl;
            window.scrollTo(0, 0);
            var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
            var height = document.documentElement.clientHeight + document.documentElement.scrollTop;
            var layer = document.createElement("div");
            layer.style.zIndex = 999;
            layer.id = "layer";
            layer.style.position = "absolute";
            layer.style.top = "0px";
            layer.style.left = "0px";
            layer.style.height = document.documentElement.scrollHeight + "px";
            layer.style.width = width + "px";
            layer.style.backgroundColor = "black";
            layer.style.opacity = "0.75";
            layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=75)");
            document.body.style.position = "static";
            
            
            document.body.appendChild(layer);
            var iframe = document.createElement("iframe");
           
            iframe.name = "Export excel by nhatnv";
            iframe.id = "popup";
            iframe.src = popUrl;
            iframe.style.height = heights + "px";
            iframe.style.width = widths + "px";
            iframe.style.position = "fixed";
            iframe.style.zIndex = 999999;
            iframe.style.backgroundColor = "white";
            iframe.frameborder = "0";
            iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (heights / 2) + "px";
            iframe.style.left = (width / 2) - (widths / 2) + "px";
            document.body.appendChild(iframe);
        }
function ClosePop() {
    var layer = document.getElementById("layer");
    var iframe = document.getElementById("popup");
    document.body.removeChild(layer); // remove layer
    document.body.removeChild(iframe); // remove div
}
function closeIframe() {
    window.parent.ClosePop();
    
}